<?php
// Module for dealing with Major requirements and requirement checking

class Course
{
	public $prefix;
	public $number;
	
	public function __construct($course_prefix, $course_number)
	{
		$this->prefix = $course_prefix;
		$this->number = $course_number;
	}
	
	public function get_name()
	{
		return "$this->prefix $this->number";
	}
}



class ISMajorRequirements
{
	private $course_array;
	
	public function __construct()
	{
		$this->course_array = array("MATH 155" => false, 
							  "MATH 215" => false, 
							  "MATH 221" => false,		 
							  "IS 147" => false, 
							  "IS 247" => false, 
							  "CMSC 201" => false, 
							  "CMSC 202" => false, 
							  "IS 300" => false, 
							  "IS 310" => false, 
							  "IS 410" => false, 
							  "IS 420" => false, 
							  "IS 425" => false, 
							  "IS 436" => false,
							  "IS 450" => false, 
							  "IS 451" => false, 
							  "IS 3XX" => false, 
							  "IS 4XX" => false, 
							  "ECAD 210" => false, 
							  "ECON 101" => false, 
							  "ECON 102" => false, 
							  "ECON 121" => false, 
							  "ECON 122" => false, 
							  "ENGL 393" => false);
	}
	
	public function add_course(Course $course)
	{
	    $course_array = $this->course_array;
	    

		if(array_key_exists($course->get_name(), $course_array))
		{
			$this->course_array[$course->get_name()] = true;
		} 
		else if($course->prefix == "IS" && (int)$course->number >= 300 && (int)$course->number < 400)
		{
			$this->course_array["IS 3XX"] = true;
		}
		else if($course->prefix == "IS" && (int)$course->number >= 400)
		{
			$this->course_array["IS 4XX"] = true;
		}
	}
	
	public function get_remaining_courses()
	{
		$array = array();
		$course_array = $this->course_array;
		if($course_array["MATH 155"] == false)
		{
			$array[] = "MATH 155";
		}
		if($course_array["MATH 215"] == false && $course_array["MATH 221"] == false)
		{
			$array[] = "MATH 215";
		}
		if($course_array["STAT 351"] == false)
		{
			$array[] = "STAT 351";
		}
		if($course_array["IS 147"] == false && $course_array["CMSC 201"] == false)
		{
			$array[] = "IS 147";
		}
		if($course_array["IS 247"] == false && $course_array["CMSC 202"] == false)
		{
			$array[] = "IS 247";
		}
		if($course_array["IS 300"] == false)
		{
			 $array[] = "IS 300";
		}
		if($course_array["IS 310"] == false)
		{
			$array[] = "IS 310";
		} 
		if($course_array["IS 410"] == false)
		{
			$array[] = "IS 410";
		}
		if($course_array["IS 420"] == false)
		{
			$array[] = "IS 420";
		}
		if($course_array["IS 425"] == false)
		{
			$array[] = "IS 425";
		}
		if($course_array["IS 436"] == false)
		{
			$array[] = "IS 436";
		}
		if($course_array["IS 450"] == false)
		{
			$array[] = "IS 450";
		}
		if($course_array["IS 451"] == false)
		{
			$array[] = "IS 451";
		}
		if($course_array["IS 3XX"] == false && $course_array["IS 4XX"] == false)
		{
			$array[] = "IS 3XX";
		}
		if($course_array["ECAD 210"] == false)
		{
			$array[] = "ECAD 210";
		}
		if($course_array["ECON 101"] == false)
		{
			$array[] = "ECON 101";
		}
		if($course_array["ECON 102"] == false)
		{
			$array[] = "ECON 102";
		}
		if($course_array["ECON 121"] == false)
		{
			$array[] = "ECON 121";
		}
		if($course_array["ECON 122"] == false)
		{
			$array[] = "ECON 122";
		}
		if($course_array["ENGL 393"] == false)
		{
			$array[] = "ENGL 393";
		}
		return $array;	
	}
}

class CMSCMajorRequirements
{
	private $course_array;
	
	public function __construct()
	{
		$this->course_array = array("CMSC 201" => false, 
							  "CMSC 202" => false, 
							  "CMSC 203" => false, 
							  "CMSC 304" => false, 
							  "CMSC 313" => false, 
							  "CMSC 331" => false, 
							  "CMSC 341" => false, 
							  "CMSC 345" => false, 
							  "CMSC 411" => false, 
							  "CMSC 421" => false, 
							  "CMSC 441" => false, 
							  "MATH 151" => false, 
							  "MATH 152" => false, 
							  "MATH 221" => false, 
							  "STAT 355" => false, 
							  "BIOL 100" => false, 
							  "BIOL 301" => false, 
							  "CHEM 101" => false, 
							  "CHEM 102" => false, 
							  "PHYS 121" => false, 
							  "PHYS 122" => false,
							  "BIOL 251" => false,
							  "BIOL 252" => false,
							  "BIOL 275" => false,
							  "BIOL 302" => false,
							  "BIOL 303" => false,
							  "BIOL 304" => false,
							  "BIOL 305" => false,
							  "GES 110" => false,
							  "GES 111" => false,
							  "GES 120" => false,
							  "CMSC 426" => false,
							  "CMSC 431" => false,
							  "CMSC 435" => false,
							  "CMSC 445" => false,
							  "CMSC 451" => false,
							  "CMSC 455" => false,
							  "CMSC 456" => false,
							  "CMSC 461" => false,
							  "CMSC 471" => false,
							  "CMSC 481" => false,
							  "CMSC 483" => false,
							  "CMSC 4X1" => false,
							  "CMSC 4X2" => false,
							  "CMSC 4X3" => false,
							  "SCI XX1" => false,
							  "SCI XX2" => false,
							  "SCI XXS" => false
							  );
	}
	
	public function add_course(Course $course)
	{
	    $course_array = $this->course_array;
	    
	    
		if(array_key_exists($course->get_name(), $course_array))
		{
			$this->course_array[$course->get_name()] = true;
		}
		if($course->prefix == "CMSC" && (int)$course->number >= 400 
		   && (int)$course->number < 495 && (int)$course->number != 404 
		   && (!array_key_exists($course->get_name(), $course_array) || 
		       (array_key_exists($course->get_name(), $course_array) && selective_number() >= 2)))
		{
			if($course_array["CMSC 4X1"])
			{
				if($course_array["CMSC 4X2"])
				{
					$this->course_array["CMSC 4X3"] = true;
				}
				else
				{
					$this->course_array["CMSC 4X2"] = true;
				}
			} 
			else 
			{
				$this->course_array["CMSC 4X1"] = true;
			}
		}
	}
	
	public function get_remaining_courses()
	{
	    $course_array = $this->course_array;
		$array = array();
		
		if($course_array["CMSC 201"] == false)
		{
			$array[] = "CMSC 201";
		}
		if($course_array["CMSC 202"] == false)
		{
			$array[] = "CMSC 202";
		}
		if($course_array["CMSC 203"] == false)
		{
			$array[] = "CMSC 203";
		}
		if($course_array["CMSC 304"] == false)
		{
			$array[] = "CMSC 304";
		}
		if($course_array["CMSC 313"] == false)
		{
			$array[] = "CMSC 313";
		}
		if($course_array["CMSC 331"] == false)
		{
			$array[] = "CMSC 331";
		}
		if($course_array["CMSC 341"] == false)
		{
			$array[] = "CMSC 341";
		}
		if($course_array["CMSC 345"] == false)
		{
			$array[] = "CMSC 345";
		}
		if($course_array["CMSC 411"] == false)
		{
			$array[] = "CMSC 411";
		}
		if($course_array["CMSC 421"] == false)
		{
			$array[] = "CMSC 421";
		}
		if($course_array["CMSC 441"] == false)
		{
			$array[] = "CMSC 441";
		}
		if($course_array["MATH 151"] == false)
		{
			$array[] = "MATH 151";
		}
		if($course_array["MATH 152"] == false)
		{
			$array[] = "MATH 152";
		}
		if($course_array["MATH 221"] == false)
		{
			$array[] = "MATH 221";
		}
		if($course_array["STAT 355"] == false)
		{
			$array[] = "STAT 355";
		}
		
	
		if($course_array["BIOL 100"] == false && 
		   $course_array["CHEM 101"] == false && 
		   $course_array["PHYS 121"] == false)
		{
			$array[] = "SCI XX1";
			$array[] = "SCI XX2";
		}
		if(!(($course_array["BIOL 100"] == true && $course_array["BIOL 301"] == true) || 
		     ($course_array["CHEM 101"] == true && $course_array["CHEM 102"] == true) ||
		     ($course_array["PHYS 121"] == true && $course_array["PHYS 122"] == true)))
		{
			if($course_array["BIOL 100"] == true && $course_array["BIOL 301"] == false)
			{
				$array[] = "BIOL 301";
			}
			else if($course_array["CHEM 101"] == true && $course_array["CHEM 102"] == false)
			{
				$array[] = "CHEM 102";
			}
			else if($course_array["PHYS 121"] == true && $course_array["PHYS 122"] == false)
			{
				$array[] = "PHYS 122";
			}
		}
		
		if(!$this->science_selective())
		{
			$array[] = "SCI XXS";
		}
		
		$count = $this->selective_number();
		if($count < 2)
		{
			for($i = 1; $i <= $count; $i++)
			{
				$array[] = "CMSC 4XS%i";
			}
		}
		
		if($course_array["CMSC 4X1"] == false)
		{
			$array[] = "CMSC 4X1";
		}
		if($course_array["CMSC 4X2"] == false)
		{
			$array[] = "CMSC 4X2";
		}
		if($course_array["CMSC 4X3"] == false)
		{
			$array[] = "CMSC 4X3";
		}
		
		return $array;
	}
	
	private function selective_number()
	{   
	
	    $course_array = $this->course_array;
	
		$count = 0;
		
		if($course_array["CMSC 426"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 431"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 435"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 445"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 451"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 455"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 456"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 461"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 471"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 481"] == true)
		{
			$count++;
		}
		if($course_array["CMSC 483"] == true)
		{
			$count++;
		}
		
		return $count;
	}

	private function science_selective()
	{
	    $course_array = $this->course_array;
	    
		$bool = false;
		if($course_array["BIOL 251"] == true)
		{
			$bool = true;	
		}
		if($course_array["BIOL 252"] == true)
		{
			$bool = true;	
		}
		if($course_array["BIOL 275"] == true)
		{
			$bool = true;	
		}
		if($course_array["BIOL 302"] == true)
		{
			$bool = true;	
		}
		if($course_array["BIOL 303"] == true)
		{
			$bool = true;	
		}
		if($course_array["BIOL 304"] == true)
		{
			$bool = true;	
		}
		if($course_array["BIOL 305"] == true)
		{
			$bool = true;	
		}
		if($course_array["GES 110"] == true)
		{
			$bool = true;	
		}
		if($course_array["GES 111"] == true)
		{
			$bool = true;	
		}
		if($course_array["GES 120"] == true)
		{
			$bool = true;	
		}
		return $bool;
	}
}

class CMSCMinorRequirements
{
	private $course_array;
	
	public function __construct()
	{
		$this->course_array = array("CMSC 201" => false, 
							  "CMSC 202" => false, 
							  "CMSC 203" => false,
							  "CMSC 313" => false, 
							  "CMSC 331" => false, 
							  "CMSC 341" => false, 
							  "CMSC 345" => false, 
							  "CMSC 411" => false, 
							  "CMSC 421" => false, 
							  "CMSC 441" => false, 
							  "MATH 221" => false, 							  
							  "CMSC 4X1" => false,
							  "CMSC 4X2" => false,
							  "CMSC 4X3" => false
							  );
	}
	
	public function add_course(Course $course)
	{
	    $course_array = $this->course_array;
	    
		if(array_key_exists($course->get_name(), $course_array))
		{
			$this->course_array[$course->get_name()] = true;
		}
		
		if($course->get_name() == "CMSC 313" || $course->get_name() == "CMSC 331" || $course->get_name() == "MATH 221")
		{
		    if($course_array["CMSC 4X1"])
			{
				$this->course_array["CMSC 4X2"] = true;
			} 
			else 
			{
				$this->course_array["CMSC 4X1"] = true;
			}
		}
		
		if($course->prefix == "CMSC" && (int)$course->number >= 400 
		   && (int)$course->number < 495 && (int)$course->number != 404 
		   && (!array_key_exists($course->get_name(), $course_array) || 
		       (array_key_exists($course->get_name(), $course_array) && selective_number() >= 2)))
		{
			if($course_array["CMSC 4X1"])
			{
				if($course_array["CMSC 4X2"])
				{
					$this->course_array["CMSC 4X3"] = true;
				}
				else
				{
					$this->course_array["CMSC 4X2"] = true;
				}
			} 
			else 
			{
				$this->course_array["CMSC 4X1"] = true;
			}
		}
	}
	
	public function get_remaining_courses()
	{
	    $course_array = $this->course_array;
		$array = array();
		
		if($course_array["CMSC 201"] == false)
		{
			$array[] = "CMSC 201";
		}
		if($course_array["CMSC 202"] == false)
		{
			$array[] = "CMSC 202";
		}
		if($course_array["CMSC 203"] == false)
		{
			$array[] = "CMSC 203";
		}
		if($course_array["CMSC 341"] == false)
		{
			$array[] = "CMSC 341";
		}
		if($course_array["CMSC 4X1"] == false)
		{
			$array[] = "CMSC 4X1";
		}
		if($course_array["CMSC 4X2"] == false)
		{
			$array[] = "CMSC 4X2";
		}
		if($course_array["CMSC 4X3"] == false)
		{
			$array[] = "CMSC 4X3";
		}
		
		return $array;
		
	}
	
}

?>